import mongoose from 'mongoose'
import config from './index'
mongoose.set('useCreateIndex', true)
mongoose.connect(config.DB_URL, {
  useNewUrlParser: true,
  useUnifiedTopology: true
})
// 连接成功
mongoose.connection.on('connected', () => {
  console.log('Mongoose is connection open to ' + config.DB_URL)
})
// 连接失败
mongoose.connection.on('error', (err) => {
  console.log(`Mongoose connection error: ${err}`)
})

mongoose.connection.on('disconnected', () => {
  console.log('Mongoose connection disconnected')
})

export default mongoose
